#ifndef GAMECONTROL_H
#define GAMECONTROL_H
#include <QObject>
#include"robot.h"
#include"cards.h"
#include"card.h"
#include"userplayer.h"
#include <QMetaType>
// template<>
// qRegisterMetaType<Cards&>("Cards&");
struct betRecord
{
    betRecord()
    {
        reset();
    }
    void reset()
    {
        player = nullptr;
        bet = 0;
        times = 0;
    }
    Player *player;
    int bet;
    int times;  //叫地主第几次了
};
class GameControl : public QObject
{
    Q_OBJECT
public:
    explicit GameControl(QObject *parent = nullptr);
    enum GameStatus{
        dispatchCard,
        CallingLord,
        PlaingHand
    };
    enum PlayerStatus{
        ThkingForCallLord,
        ThkingForPlayHand,
        Winning
    };

    void playerInit();

    Robot* getLeftRobot();
    Robot* getRightRobot();
    UserPlayer* getUserPlayer();

    void setCurPlayer(Player *player);
    Player* getCurPlayer();

    Player* getPendPlayer();
    Cards getPendCards();

    void InitAllCards();

    Card takeOneCard();
    Cards getSurplusCards();

    void resetCardsData();

    void startLandLord();
    void becomeLord(Player *player,int bet);
    void clearPlayerScore();
    void onGrabBet(Player *player , int bet);
    int getmaxLordbet();
    void onPlayHand(Player *player,Cards& cards);

signals:
    void playerStatusChanged(Player *player,PlayerStatus status);
    void notifyGrabLordBet(Player *player,int bet,bool flag);
    void gameStatusChanged(GameStatus status);
    void notifyPlayHand(Player *player,Cards &cards);
    void pendingInfo(Player *player,Cards &cards);
private:
    Robot *m_robotLeft= nullptr;
    Robot *m_robotRight= nullptr;
    UserPlayer *m_user= nullptr;
    Player *m_curPlayer= nullptr;
    Player *m_pendPlayer= nullptr;
    Cards m_pendCard;
    Cards m_allCards;
    betRecord m_betRecord;
    int m_curbet = 0;

};

#endif // GAMECONTROL_H
